from rest_framework import serializers
from .models import *

# from myapp.models import Thing, Classification, Tag, User, Comment, Record, LoginLog, OpLog, Banner, \
#     Ad, Notice, ErrorLog, Address

# 为什么要将每一个序列化都存到数据库中？？？
# 这个不是每个都要保存在数据库中
# 使用数据库中的字段和传入的字段进行比较
# 如果需要可以将他们更新进数据库
class UserSerializer(serializers.ModelSerializer):
    create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)

    class Meta:
        model = User # 属性指定了所序列化的模型类
        fields = '__all__' # 应该包含模型中的所有字段
        # exclude = ('password',) # 指定字符串列表应该排除password


class LoginLogSerializer(serializers.ModelSerializer):
    # 当定义的字段属性不同时，两处会相互补充
    log_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)

    class Meta:
        model = LoginLog
        fields = '__all__'


class OpLogSerializer(serializers.ModelSerializer):
    re_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)

    class Meta:
        model = OpLog
        fields = '__all__'


class ErrorLogSerializer(serializers.ModelSerializer):
    log_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)

    class Meta:
        model = ErrorLog
        fields = '__all__'
